<%@page import="weaver.conn.RecordSet"%>
<%@page import="java.sql.Statement"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@ page import="com.alibaba.fastjson.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.sql.ResultSet" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
    try {
        // URL 参数
        Object awardsSubnameIdObj = request.getParameter("awardsSubnameId");
        Object searchKey = request.getParameter("searchKey");
        JSONArray array = new JSONArray();
        if(awardsSubnameIdObj == null){
            retObject.put("code", -1);
            retObject.put("msg", "awardsSubnameId 不能为空");
        }else {
        	
        	Integer awardsSubnameId =  Integer.parseInt(awardsSubnameIdObj.toString());
        	String querySubAwardSql = "select * from vote_awards_subname where id = "+awardsSubnameId;
        	 RecordSet set0  = new RecordSet();
        	 String status = "0";
             set0.executeSql(querySubAwardSql);
             if(set0.next()){
            	 retObject.put("awardSubStatus", set0.getString("status")); 
             }
            // 数据库查询
          	String sql =  "select * from vote_awards_participator vap where vap.awards_subname_id ="+awardsSubnameId +" and vap.is_del = 0";
          	if(null!=searchKey &&!"".equals(searchKey)){
          		sql +=" AND (  vap.member_names like N'%"+searchKey+"%' "; 
    			sql +="	or vap.applicant_name like N'%"+searchKey+"%'  ";
    			sql +="	or vap.applicant_position like N'%"+searchKey+"%'  ";
    			sql +="	or vap.applicant_dept_name like N'%"+searchKey+"%'  ";
    			sql +="	or vap.nominator_name like N'%"+searchKey+"%'  ";
    			sql +="	or vap.nominator_dept_name like N'%"+searchKey+"%'  ";
    			sql +="	or vap.nominator_project_name like N'%"+searchKey+"%'  ";
    			sql +="	or vap.nominator_position like N'%"+searchKey+"%'  ";
    			sql +=")  order by vap.id DESC" ;
          	}
            RecordSet set  = new RecordSet();
            set.executeSql(sql);
            while(set.next()){
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id",set.getInt("id"));                                      // 参与名单id
                jsonObject.put("pojectNum",set.getString("poject_num"));                     // 项目编号
                jsonObject.put("nominatorProjectName",set.getString("nominator_project_name"));// 提名项目名称
                jsonObject.put("applicantName",set.getString("applicant_name"));             // 申请人名称
                jsonObject.put("applicantDeptName",set.getString("applicant_dept_name"));    // 申请人部门名称
                jsonObject.put("applicantPosition",set.getString("applicant_position"));     // 申请人职位
                jsonObject.put("nominatorName",set.getString("nominator_name"));             // 被提名名称
                jsonObject.put("nominatorDeptName",set.getString("nominator_dept_name"));    // 被提名部门名称
                jsonObject.put("nominatorPosition",set.getString("nominator_position"));     // 被提名职位
                jsonObject.put("nominatorPhoto",set.getString("nominator_photo"));           // 被提名照片（参与人头像）
                jsonObject.put("nominatorType",set.getString("nominator_type"));                // 被提名类型：1 个人 2 团队
                jsonObject.put("nominatorPosition",set.getString("nominator_position"));     // 被提名类型：1 个人 2 团队
                jsonObject.put("nominatorStatus",set.getString("nominator_status"));            // 被提名状态：0 待提名 1 提名中 -1 提名驳回
                jsonObject.put("winStatus",set.getString("win_status"));                    	// 获奖状态：0 未获将 1 获奖
                jsonObject.put("flowerNum",set.getString("flower_num"));                        // 送花数量
                jsonObject.put("messageNum",set.getString("message_num"));                      // 留言数量
                jsonObject.put("votesNum",set.getString("votes_num"));                          // 得票数量
                jsonObject.put("memberNames",set.getString("member_names"));
                array.add(jsonObject);
            }
            retObject.put("data", array);
        }
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        if (printWriter != null)  printWriter.close();
    }
%>
 